package cn.zwx.member.svc.facade;

import cn.zwx.base.entity.ResponseEntity;
import cn.zwx.base.exception.BizWrapException;
import cn.zwx.member.svc.dto.AddressCreateReqDTO;
import cn.zwx.member.svc.dto.AddressQueryDTO;
import cn.zwx.member.svc.dto.AddressUpdateReqDTO;
import cn.zwx.member.svc.fallback.AddressApiFallback;
import cn.zwx.member.svc.vo.AddressRespVO;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author zhangwenxue
 */
@FeignClient(name = "member-svc",path = "/address")
public interface AddressServiceApi extends FallbackFactory<AddressApiFallback> {

    @PostMapping
    AddressApiFallback create(Throwable cause);

    @PostMapping("/create")
    @ApiOperation("创建用户收件地址")
    ResponseEntity<Long> createAddress(@Valid @RequestBody AddressCreateReqDTO dto) throws BizWrapException;


    @PutMapping("/update")
    @ApiOperation("更新用户收件地址")
    ResponseEntity<Boolean> updateAddress(@Valid @RequestBody AddressUpdateReqDTO dto) throws BizWrapException;

    @DeleteMapping("/delete")
    @ApiOperation("删除用户收件地址")
    ResponseEntity<Boolean> deleteAddress(@Valid@NotNull(message = "地址编号不能为空")
                                          @ApiParam(value = "地址编号",required = true)
                                          @RequestParam("id") Long id,@NotNull(message = "用户id不能为空")
                                          @ApiParam(value = "用户id",required = true)
                                          @RequestParam("userId") Long userId) throws BizWrapException;

    @GetMapping("/get")
    @ApiOperation("获得用户收件地址")
    ResponseEntity<AddressRespVO> getAddress(@Valid AddressQueryDTO dto) throws BizWrapException;

    @GetMapping("/get-default")
    @ApiOperation( "获得默认的用户收件地址")
    ResponseEntity<AddressRespVO> getDefaultUserAddress(@Valid@NotNull(message = "用户id不能为空")
                                                        @ApiParam(value = "用户id",required = true)
                                                        @RequestParam("userId") Long userId) throws BizWrapException;

    @GetMapping("/list")
    @ApiOperation("获得用户收件地址列表")
    ResponseEntity<List<AddressRespVO>> getAddressList(@Valid@NotNull(message = "用户id不能为空")
                                                       @ApiParam(value = "用户id",required = true)
                                                       @RequestParam("userId") Long userId) throws BizWrapException;

}
